package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.SysUserImel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.system.service.ISysUserImelService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户设备关系Controller
 * 
 * @author ruoyi
 * @date 2021-08-11
 */
@RestController
@RequestMapping("/imel")
public class SysUserImelController extends BaseController
{
    @Autowired
    private ISysUserImelService sysUserImelService;

    /**
     * 查询用户设备关系列表
     * 用户通过短信登陆时，需要绑定设备号，所以无法加权限控制
     */
//    @PreAuthorize(hasPermi = "system:imel:list")
    @GetMapping("/list")
    public TableDataInfo list(SysUserImel sysUserImel)
    {
        startPage();
        List<SysUserImel> list = sysUserImelService.selectSysUserImelList(sysUserImel);
        return getDataTable(list);
    }

    /**
     * 导出用户设备关系列表
     */
    @PreAuthorize(hasPermi = "system:imel:export")
    @Log(title = "用户设备关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserImel sysUserImel) throws IOException
    {
        List<SysUserImel> list = sysUserImelService.selectSysUserImelList(sysUserImel);
        ExcelUtil<SysUserImel> util = new ExcelUtil<SysUserImel>(SysUserImel.class);
        util.exportExcel(response, list, "用户设备关系数据");
    }

    /**
     * 获取用户设备关系详细信息
     */
    @PreAuthorize(hasPermi = "system:imel:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysUserImelService.selectSysUserImelById(id));
    }

    /**
     * 新增用户设备关系
     * 用户通过短信登陆时，需要绑定设备号，所以无法加权限控制
     */
//    @PreAuthorize(hasPermi = "system:imel:add")
    @Log(title = "用户设备关系", businessType = BusinessType.INSERT)
    @PostMapping("/bandImel")
    public AjaxResult add(@RequestBody SysUserImel sysUserImel)
    {
        return toAjax(sysUserImelService.insertSysUserImel(sysUserImel));
    }

    /**
     * 修改用户设备关系
     */
    @PreAuthorize(hasPermi = "system:imel:edit")
    @Log(title = "用户设备关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserImel sysUserImel)
    {
        return toAjax(sysUserImelService.updateSysUserImel(sysUserImel));
    }

    /**
     * 删除用户设备关系
     */
    @PreAuthorize(hasPermi = "system:imel:remove")
    @Log(title = "用户设备关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUserImelService.deleteSysUserImelByIds(ids));
    }
}
